////////////////////////////////////////////////////////////////////////////////
// Copyright 2010 Michael Schmalle - Teoti Graphix, LLC
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
// http://www.apache.org/licenses/LICENSE-2.0 
// 
// Unless required by applicable law or agreed to in writing, software 
// distributed under the License is distributed on an "AS IS" BASIS, 
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and 
// limitations under the License
// 
// Author: Michael Schmalle, Principal Architect
// mschmalle at teotigraphix dot com
////////////////////////////////////////////////////////////////////////////////

package fxplugins.registry.restricted
{

import fxplugins.registry.IContributor;
import fxplugins.registry.IExtension;
import fxplugins.registry.IExtensionDescriptor;

/**
 * 
 * 
 * @author Michael Schmalle
 * @copyright Teoti Graphix, LLC
 * @productversion 1.0
 */
public class RegistryExtension extends RegistryClient implements IExtension
{
	public var contributorID:int;
	
	//--------------------------------------------------------------------------
	//
	//  IExtension API :: Properties
	//
	//--------------------------------------------------------------------------
	
	//----------------------------------
	//  contributor
	//----------------------------------
	
	/**
	 * @copy fxplugins.registry.IExtension#contributor
	 */
	public function get contributor():IContributor
	{
		return registry.getContributor(contributorID);
	}
	
	//----------------------------------
	//  simpleID
	//----------------------------------
	
	/**
	 * @private
	 */
	private var _simpleID:String;
	
	/**
	 * @copy fxplugins.registry.IExtension#simpleID
	 */
	public function get simpleID():String
	{
		return _simpleID;
	}
	
	/**
	 * @private
	 */
	public function set simpleID(value:String):void
	{
		_simpleID = value;
	}
	
	//----------------------------------
	//  namespaceID
	//----------------------------------
	
	/**
	 * @private
	 */
	private var _namespaceID:String;
	
	/**
	 * @copy fxplugins.registry.IExtension#namespaceID
	 */
	public function get namespaceID():String
	{
		return _namespaceID;
	}
	
	/**
	 * @private
	 */
	public function set namespaceID(value:String):void
	{
		_namespaceID = value;
	}
	
	//----------------------------------
	//  uniqueID
	//----------------------------------
	
	/**
	 * @copy fxplugins.registry.IExtension#uniqueID
	 */
	public function get uniqueID():String
	{
		return _simpleID == null || _simpleID == ""
			? null :
			_namespaceID + "." + _simpleID;
	}
	
	//----------------------------------
	//  internalID
	//----------------------------------
	
	/**
	 * @copy fxplugins.registry.IExtension#internalID
	 */
	public function get internalID():int
	{
		return registryID;
	}
	
	//----------------------------------
	//  extensionPointID
	//----------------------------------
	
	/**
	 * @private
	 */
	private var _extensionPointID:String;
	
	/**
	 * @copy fxplugins.registry.IExtension#extensionPointID
	 */
	public function get extensionPointID():String
	{
		return _extensionPointID;
	}
	
	/**
	 * @private
	 */
	public function set extensionPointID(value:String):void
	{
		_extensionPointID = value;
	}
	
	//----------------------------------
	//  label
	//----------------------------------
	
	/**
	 * @private
	 */
	private var _label:String;
	
	/**
	 * @copy fxplugins.registry.IExtension#label
	 */
	public function get label():String
	{
		return _label;
	}
	
	/**
	 * @private
	 */
	public function set label(value:String):void
	{
		_label = value;
	}
	
	//--------------------------------------------------------------------------
	//
	//  Constructor
	//
	//--------------------------------------------------------------------------
	
	/**
	 * Constructor.
	 * @private
	 */
	public function RegistryExtension(registry:ExtensionRegistry, 
									  registryID:int, 
									  children:Array = null)
	{
		super(registry, registryID);
		
		this.children = children;
	}
	
	/**
	 * @copy IExtension#getExtensionDescriptors()
	 */
	public function getExtensionDescriptors():Array // of IExtensionDescriptor
	{
		return registry.getExtensionDescriptors(this);
	}

	
	
	public function getChild(name:String):IExtensionDescriptor
	{
		var list:Array = getExtensionDescriptors();
		for each (var item:IExtensionDescriptor in list)
		{
			if (item.name == name)
			{
				return item;
			}
		}
		return null;
	}
}
}